From: Matthew Daley Date: Mon, 2 Dec 2013 00:27:27 +0000 (+1300) Subject: libxl: don't leak p in libxl__wait_for_backend X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5831 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=0ca009727b3ea5b17046e0ee990238e9488eab9c;p=xen.git libxl: don't leak p in libxl__wait_for_backend Use libxl__xs_read_checked instead of xs_read. While at it, tidy up the function as well. Coverity-ID: 1055891 Signed-off-by: Matthew Daley Reviewed-by: Andrew Cooper Acked-by: Ian Jackson --- diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index d995c835db..ba7d100d0e 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1199,37 +1199,30 @@ int libxl__wait_for_device_model_deprecated(libxl__gc *gc, check_callback, check_callback_userdata); } -int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state) +int libxl__wait_for_backend(libxl__gc *gc, const char *be_path, + const char *state) { - libxl_ctx *ctx = libxl__gc_owner(gc); int watchdog = 100; - unsigned int len; - char *p; - char *path = GCSPRINTF("%s/state", be_path); - int rc = -1; + const char *p, *path = GCSPRINTF("%s/state", be_path); + int rc; + + while (watchdog-- > 0) { + rc = libxl__xs_read_checked(gc, XBT_NULL, path, &p); + if (rc) return rc; - while (watchdog > 0) { - p = xs_read(ctx->xsh, XBT_NULL, path, &len); if (p == NULL) { - if (errno == ENOENT) { - LOG(ERROR, "Backend %s does not exist", be_path); - } else { - LOGE(ERROR, "Failed to access backend %s", be_path); - } - goto out; - } else { - if (!strcmp(p, state)) { - rc = 0; - goto out; - } else { - usleep(100000); - watchdog--; - } + LOG(ERROR, "Backend %s does not exist", be_path); + return ERROR_FAIL; } + + if (!strcmp(p, state)) + return 0; + + usleep(100000); } + LOG(ERROR, "Backend %s not ready", be_path); -out: - return rc; + return ERROR_FAIL; } /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a2d8247f38..1bd23ff295 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -944,7 +944,8 @@ _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device); _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, libxl__device *dev); _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev); -_hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +_hidden int libxl__wait_for_backend(libxl__gc *gc, const char *be_path, + const char *state); _hidden int libxl__nic_type(libxl__gc *gc, libxl__device *dev, libxl_nic_type *nictype);